package com.weslide.weslideapp.parser;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.weslide.weslideapp.pojo.ao.ShopTypeAO;
import com.weslide.weslideapp.pojo.ao.ShopTypeList;

public class GetShopTypeParser {
	private ShopTypeList shopTypeListAO = new ShopTypeList();

	public void parser(String jsonString) throws JSONException {
		JSONArray jsonArray = new JSONArray(jsonString);
		JSONObject statusJsonObject = jsonArray.getJSONObject(0);
		shopTypeListAO.setStatus(statusJsonObject.getString("status"));
		if (shopTypeListAO.getStatus().equals("1")) {
			for (int i = 1; i < jsonArray.length(); i++) {
				ShopTypeAO shopTypeAO = new ShopTypeAO();
				JSONObject dataJsonObject = jsonArray.getJSONObject(i);
				shopTypeAO.setShopTypeId(dataJsonObject
						.getString("shoptype_id"));
				shopTypeAO.setName(dataJsonObject.getString("name"));
				shopTypeListAO.addShopType(shopTypeAO);
			}
		}
	}

	public ShopTypeList getData() {
		return shopTypeListAO;
	}
}